package isssr.bean.entity;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;

@Entity
public class OrganizationalGoal extends MetaEntity{

	private Integer 	id;
	private String 		title;
	private String 		description;
	private Integer 	priority;
	private Integer 	status;
	private User 		goalOwner;
	private User 		goalEnactor;
	private Set<User> 	superList;
	private String 		focus;
	private String 		object;
	private String 		magnitude;
	private String 		timeframe;
	private String 		organizationalScope;
	private String 		constraints;
	private String 		relations;

	protected Serializable getMetaID()
	{
		return this.id;
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public OrganizationalGoal() {
		this.superList = new HashSet<User>();
	}
	
	public User getGoalOwner() {
		return goalOwner;
	}

	public void setGoalOwner(User goalOwner) {
		this.goalOwner = goalOwner;
	}

	public User getGoalEnactor() {
		return goalEnactor;
	}

	public void setGoalEnactor(User goalEnactor) {
		this.goalEnactor = goalEnactor;
	}

	public Set<User> getSuperList() {
		return superList;
	}

	public void setSuperList(Set<User> superList) {
		this.superList = superList;
	}

	public String getFocus() {
		return focus;
	}

	public void setFocus(String focus) {
		this.focus = focus;
	}

	public String getObject() {
		return object;
	}

	public void setObject(String object) {
		this.object = object;
	}

	public String getMagnitude() {
		return magnitude;
	}

	public void setMagnitude(String magnitude) {
		this.magnitude = magnitude;
	}

	public String getTimeframe() {
		return timeframe;
	}

	public void setTimeframe(String timeframe) {
		this.timeframe = timeframe;
	}

	public String getOrganizationalScope() {
		return organizationalScope;
	}

	public void setOrganizationalScope(String organizationalScope) {
		this.organizationalScope = organizationalScope;
	}

	public String getConstraints() {
		return constraints;
	}

	public void setConstraints(String constraints) {
		this.constraints = constraints;
	}

	/*
	public List<String> getRelations() {
		return relations;
	}

	public void setRelations(List<String> relations) {
		this.relations = relations;
	}
	 */
	public String getTitle() {
		return title;
	}

	public void setTitle(String name) {
		this.title = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	

	public GoalStatus getEnumStatus() {
		
		switch(this.status.intValue())
		{
			case 0 : return GoalStatus.DEFINITION;
			case 1 : return GoalStatus.ELICITATION_VOTE;
			case 2 : return GoalStatus.FEASIBILITY_ANALYSIS;
			case 3 : return GoalStatus.DEVELOPEMENT;
			case 4 : return GoalStatus.COMPLETED;
			default: return null;
		}
	}

	public void setEnumStatus(GoalStatus status) {
	
		Integer newStatus;
		
		switch(status)
		{
			case DEFINITION : 
				newStatus = 0;
				break;
			case ELICITATION_VOTE:
				newStatus = 1;
				break;
			case FEASIBILITY_ANALYSIS:
				newStatus = 2;
				break;
			case DEVELOPEMENT:
				newStatus = 3;
				break;
			case COMPLETED:
				newStatus = 4;
				break;
			default:
				newStatus = null;	
				break;
		}
		
		this.status = newStatus;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public String getRelations() {
		return relations;
	}

	public void setRelations(String relations) {
		this.relations = relations;
	}

	public void setDefaultTitle()
	{
		if(title == null)
		{
			title = "OrganizationalGoal_";
		}
	}
	
	public boolean equals(Object o)
	{
		if(o==null)
			return false;
		
		if(this == o) 
			return true;
		
		if(this.getClass() != o.getClass())
			return false;
		
		OrganizationalGoal otherGoal = (OrganizationalGoal) o;
		Object thisValue;
		Object otherValue;
		
		try
		{
			for(Field f : this.getClass().getDeclaredFields())
			{
				thisValue = f.get(this);
				otherValue = f.get(otherGoal);
				
				if(thisValue==null)
				{
					if(otherValue!=null)
						return false;
				}
				else if(!thisValue.equals(otherValue))
				{
					return false;
				}
			}
		}
		catch(IllegalArgumentException ex)
		{
			ex.printStackTrace();
			return false;
		}
		catch(IllegalAccessException ex)
		{
			ex.printStackTrace();
			return false;
		}
		
		return true;
	}

}
